package com.megvii.corelib.components;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.megvii.corelib.R;

/**
 * Created by linyue on 15/12/23.
 */
public class NetworkErrorView extends RelativeLayout implements BaseNetworkErrorView
{
    private Button button;

    private ButtonListener listener;

    public NetworkErrorView(Context context)
    {
        super(context);
        init();
    }

    public NetworkErrorView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        init();
    }

    public NetworkErrorView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        init();
    }

    public void setButtonListener(ButtonListener listener)
    {
        this.listener = listener;
    }

    @Override
    public void show()
    {
        setVisibility(View.VISIBLE);
    }

    @Override
    public void hide()
    {
        setVisibility(View.GONE);
    }

    private void init()
    {
        inflate(getContext(), getLayoutResId(), this);
        button = (Button) findViewById(R.id.netwokError_layout_rel_btn);
        button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v)
    {
        if (listener != null)
        {
            listener.onNetworkErrorButtonClick();
        }
    }

    protected int getLayoutResId()
    {
        return R.layout.networkerror_layout;
    }
}
